package com.cf.track;

/**
 * boot-common-TrackUtil
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/9/11 上午 11:07
 */
public class TrackUtil {

    public static String trackString(StackTraceElement[] stackTraceElements) {
        StackTraceElement[] st = stackTraceElements;
        if (st == null) {
            return "无";
        }
        StringBuffer sbf = new StringBuffer();
        for (StackTraceElement e : st) {
            if (sbf.length() > 0) {
                sbf.append(" <- ");
                sbf.append(System.getProperty("line.separator"));
            }
            sbf.append(java.text.MessageFormat.format("{0}.{1}() {2}"
                    , e.getClassName()
                    , e.getMethodName()
                    , e.getLineNumber()));
        }
        return sbf.toString();
    }

    public static String trackString(Exception exception) {
        return trackString(exception.getStackTrace());
    }

}
